package com.leoman.plz_p.weidget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.leoman.plz_p.R;

import cn.com.corelib.utils.DisplayUtil;


/**
 * Created by guoh on 2018/7/7.
 */
public class CommitSuccessDialog extends Dialog {

    private RelativeLayout layout;
    private TextView tv_grade;
    private TextView tv_mistake_num;
    private TextView tv_see_mistake;
    private ImageView iv_close;

    public CommitSuccessDialog(@NonNull Context context) {
        super(context);
    }

    public CommitSuccessDialog(@NonNull Context context, int themeResId) {
        super(context, R.style.DialogStyle);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.view_commit_success);
        layout=findViewById(R.id.rl_layout);
        tv_grade=findViewById(R.id.tv_text);
        tv_mistake_num=findViewById(R.id.tv_text1);
        tv_see_mistake=findViewById(R.id.tv_see_mistake);
        findViewById(R.id.iv_close).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        Window win = getWindow();
        WindowManager.LayoutParams lp = win.getAttributes();
        lp.gravity = Gravity.CENTER;
        LinearLayout.LayoutParams params= (LinearLayout.LayoutParams) layout.getLayoutParams();
        params.height=(int) (DisplayUtil.getScreenDispaly(getContext())[1]*0.35);
        params.width=(int) (DisplayUtil.getScreenDispaly(getContext())[0]*0.83);
        getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        win.setAttributes(lp);
    }

    public void setScoreAndMistakeCount(String score,int mistakeCount){
        tv_grade.setText("考试得分"+score+"分");
        tv_mistake_num.setText("答错"+mistakeCount+"题");
    }

    public void setSeeMistakeOnClickListener(View.OnClickListener ls){
        tv_see_mistake.setOnClickListener(ls);
    }
}
